/*
 * Copyright (c) 2010, Nikolaus Moll
 * All rights reserved.
 */
package net.miblounge.gradecalculator.core.descriptors;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(namespace = "http://gradecalculator.net/")
@XmlType( 
 propOrder = { "id", "name" } 
) 
public class Descriptor {
	private String id = null;
	private String name = null;
	private boolean added = false;
	
	public Descriptor()
	{
	}
	
	public Descriptor(final String id, final String name)
	{
		this.id = id;
		this.name = name;
	}

	@XmlElement(name = "id")
	public String getId() {
		return id;
	}
	public void setId(final String id) {
		this.id = id;
		addIfPossible();
	}
	
	@XmlElement(name = "name")
	public String getName() {
		return name;
	}
	public void setName(final String name) {
		this.name = name;
		addIfPossible();
	}
	
	private void addIfPossible()
	{
		if ((added) || (name == null) || (id == null)) {
			return;
		}
		
		addToList();
		added = true;
	}
	
	protected void addToList()
	{
	}
	
	@Override
	public int hashCode() {
		int result = 17;
		result = 31 * result + id.hashCode();
		result = 31 * result + name.hashCode();
		return result;
	}	
}
